# Reference: <https://postmarketos.org/vendorkernel>
# Kernel config based on: arch/arm/configs/eagle_ss_defconfig

pkgname=linux-sony-eagle
pkgver=3.4.0
pkgrel=2
pkgdesc="Sony Xperia M2 kernel fork"
arch="armv7"
_carch="arm"
_flavor="sony-eagle"
url="https://kernel.org"
license="GPL-2.0-only"
options="!strip !check !tracedeps pmb:cross-native"
makedepends="bash bc bison devicepkg-dev flex openssl-dev perl dtbtool gcc4"

# Compiler: this kernel was only tested with GCC4. Feel free to make a merge
# request if you find out that it is booting working with newer GCCs as
# well. See <https://postmarketos.org/vendorkernel> for instructions.
if [ "${CC:0:5}" != "gcc4-" ]; then
	CC="gcc4-$CC"
	HOSTCC="gcc4-gcc"
	CROSS_COMPILE="gcc4-$CROSS_COMPILE"
fi

# Source
_repository="android_kernel_sony_msm8226"
_commit="53fc207771ed87a44d9f7c73058f4638b883e474"
_primacommit="79403896e1c410582044c50dfce92d5e97233e0c"
_config="config-$_flavor.$arch"
source="
	$pkgname-$_commit.tar.gz::https://github.com/ilpianista/$_repository/archive/$_commit.tar.gz
	$pkgname-prima-$_primacommit.tar.gz::https://source.codeaurora.org/external/wlan/prima/snapshot/$_primacommit.tar.gz
	$_config
	timeconst.pl-Eliminate-Perl-warning.patch
	02_reduce_lzo_compression.patch
	03_fix_add_uevent_var.patch
	linux3.4-vfs-Fix-proc-tid-fdinfo-fd-file-handling.patch
	gcc-wrapper-port-to-py3.patch
	gcc10-extern_YYLOC_global_declaration.patch
"
builddir="$srcdir/$_repository-$_commit"
_primadir="$srcdir/$_primacommit"
_outdir="out"

prepare() {
	default_prepare
	. downstreamkernel_prepare
}

build() {
	unset LDFLAGS

	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-postmarketOS"

	make O="$_outdir" ARCH="$_carch" CC="${CC:-gcc}" \
		-C "$builddir" M="$_primadir" CONFIG_PRONTO_WLAN=m CONFIG_PRIMA_WLAN_LFR=y \
		CONFIG_QCOM_TDLS=y CONFIG_ENABLE_LINUX_REG=y \
		KERNEL_BUILD=1 WLAN_ROOT="$_primadir" modules
}

package() {
	downstreamkernel_package "$builddir" "$pkgdir" "$_carch" "$_flavor" "$_outdir"

	mkdir -p "$pkgdir"/lib/modules/$pkgver
	install -Dm644 "$_primadir"/wlan.ko "$pkgdir"/lib/modules/$pkgver/

	# Master DTB (deviceinfo_bootimg_qcdt)
	dtbTool -p scripts/dtc/ -o "$_outdir/arch/$_carch/boot"/dt.img "$_outdir/arch/$_carch/boot/"
	install -Dm644 "$_outdir/arch/$_carch/boot"/dt.img "$pkgdir"/boot/dt.img
}

sha512sums="4c5a675e2583480cf91ddd73527cb26480fd0d385427b5d6fd6a4e975cfe8d979a647451291c8d123cff66efbc1f97baa87b4eb8be4d7745f739d4bda5ea081e  linux-sony-eagle-53fc207771ed87a44d9f7c73058f4638b883e474.tar.gz
f9e75725bd2c8e8e65af0ed07601aa9cfb3404653b94cb249d2e063be2877e0738fcbcdfb8bfefeaba7aafc2f542735e0af56a586a22340889922e7db469f0fb  linux-sony-eagle-prima-79403896e1c410582044c50dfce92d5e97233e0c.tar.gz
6cfc15f7bb7c95f18067e2fd3d0c45f6d89aca3eec72ad55e5b8141201695af9cda720c953b0a5eeb17f7c4f7a747ea93be2247ddcbbefabab98d67d996af70c  config-sony-eagle.armv7
1fcfb5f06a2bfdcc55d53054ca80d1b989599a39a5379d057a0724fc405187d74da4309a650e70b9c79d39444e81923cfc5c9199ed8c0a77c83dcd7998446bb7  timeconst.pl-Eliminate-Perl-warning.patch
30ac7171fe2a5aa90c15e56465b35bfc84015079296df2ebbb4287a2848ac5e8cf8e0dbb00dfdf84acb6692587eefdfc338e65ef3170a1a3e5b279b317ba43f3  02_reduce_lzo_compression.patch
72553b9283552fd003ee50e93a96c358184503e02500ca0b1790eb5e5e16c308193c04ee881dbf447424bba50afa2d1e38ad01a1d34482dcc17e73a337e07026  03_fix_add_uevent_var.patch
5e81c20b0b30c1ab09bd59f1e1b77fcce945a27de8144c68617ddc5e8f10e1f6fa8b1e4cd5d63e43511d61dace46fb26b14a6227a667b9718d44c8b81dbe6100  linux3.4-vfs-Fix-proc-tid-fdinfo-fd-file-handling.patch
13e289c889a48946cd3d976932f06f749bed5c6596776f4b683aada4e3e2f50b66286d6f550b8f2e260b58867b759591bbf8b54cc07ad9d3bb761ff477f036a1  gcc-wrapper-port-to-py3.patch
2b48f1bf0e3f70703d2cdafc47d5e615cc7c56c70bec56b2e3297d3fa4a7a1321d649a8679614553dde8fe52ff1051dae38d5990e3744c9ca986d92187dcdbeb  gcc10-extern_YYLOC_global_declaration.patch"
